package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.NewAddressView;


import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Hu on 2016/10/13.
 */

public class NewAddressP extends BasePresenter implements VolleyCallBack<JSONObject> {
    NewAddressView newAddressView;

    public NewAddressP(NewAddressView newAddressView) {

        this.newAddressView = newAddressView;
    }

    @Override
    public void addData(String url) {
        sendJsonObjectUrl(url,this);
    }

    @Override
    public void onResponse(JSONObject object) {
        int succeed = 0;
        try {
            succeed = object.getInt("res");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (succeed==1){
            newAddressView.succed();
        }else if (succeed==0){
            newAddressView.errored();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
    }
}
